package com.wzqj.agent.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.wzqj.agent.common.Log;
import com.wzqj.agent.web.service.DeviceService;

@Controller
@RequestMapping("/device")
public class DeviceWebContrpller {

	@Autowired
	private DeviceService deviceService;
	/**
	 * 绑定设备
	 * @param mcode
	 * @param en
	 * @return
	 */
	@RequestMapping("/bindDevice")
	@ResponseBody
	public JSONObject bindDevice(String mcode,String en){
		JSONObject data = new JSONObject();
		
		try {
			JSONObject device = deviceService.bindDeviceToStore(mcode, en);
			if (device==null) {
				data.put("status",1);
				data.put("info", "绑定设备失败！");
				return data;
			}
			data.put("status",0);
			data.put("info", "绑定设备成功！");
			data.put("data", device);
			
		} catch (Exception e) {
			data.put("status",1);
			data.put("info", "绑定设备失败！");
			Log.run.error(e.getMessage());
			e.printStackTrace();
		}
				
		return data;
	}
	/**
	 * 批量绑定设备（备用）
	 * @param mcode
	 * @param ens
	 * @return
	@RequestMapping("/bindDeviceByEns")
	@ResponseBody
	public JSONObject bindDevice2(String mcode,String ens){
		JSONObject data = new JSONObject();
		try {
		
			JSONObject device = deviceService.bindDevicesToStore(mcode, ens);
			//System.out.println("device:"+device);
			if (device==null) {
				data.put("status",0);
				data.put("info", "绑定设备失败！");
				return data;
			}
			data.put("status",1);
			data.put("info", "绑定设备成功！");
			data.put("data", device);
			
		} catch (Exception e) {
			data.put("status",0);
			data.put("info", "绑定设备失败！");
			Log.run.error(e.getMessage());
			e.printStackTrace();
		}
				
		return data;
	}
	 */
}
